package com.hw.controller.basic;

import com.hw.entity.dto.basic.StoreInfoDTO;
import com.hw.entity.query.basic.StoreInfoQuery;
import com.hw.entity.vo.basic.StoreInfoVO;
import com.hw.model.ResponseResult;
import com.hw.service.basic.StoreInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 商家信息
 *
 * @author whw
 * @date 2021/6/24
 */
@Api(tags = "商家信息")
@RestController()
@RequestMapping("/store")
public class StoreController {
    @Autowired
    StoreInfoService storeInfoService;

    @ApiOperation(value = "获取列表")
    @GetMapping("/list")
    public ResponseResult<List<StoreInfoVO>> list(StoreInfoQuery query) {
        return ResponseResult.success(storeInfoService.list(query));
    }

    @ApiOperation(value = "保存图片")
    @PostMapping("/saveImg")
    public ResponseResult<?> saveImg(@RequestParam(value = "file") MultipartFile file, @RequestParam(value = "storeId") String storeId) {

        storeInfoService.updateAvatar(file, storeId);
        return ResponseResult.success();
    }

    @ApiOperation(value = "保存")
    @PostMapping("/save")
    public ResponseResult<?> save(@RequestBody StoreInfoDTO dto) {
        return storeInfoService.save(dto);
    }

    @ApiOperation(value = "删除")
    @GetMapping("/delete")
    public ResponseResult<?> delete(String storeId) {
        return storeInfoService.delete(storeId);
    }

    @ApiOperation(value = "获取详情")
    @GetMapping("/getDetail")
    public ResponseResult<?> getDetail(String storeId) {
        if (null == storeInfoService.getDetail(storeId)) {
            ResponseResult.error("获取失败！");
        }
        return ResponseResult.success(storeInfoService.getDetail(storeId));
    }
}
